public class Test {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {5,7,7,8,8,10};
        int target = 8;
        int[] arr = new int[2];
        arr = solution.searchRange(nums,target);
        System.out.println(arr[0]);
        System.out.println(arr[1]);
    }
}

class Solution {
    public int[] searchRange(int[] nums, int target) {
        int[] arr = new int[]{-1,-1};
        //特殊情况处理
        if(nums.length == 0){
            return arr;
        }


        int left = 0, right = nums.length - 1;
        int mid = 0;
        //寻找左端点
        while (left < right) {
            mid = left + (right - left)/2;
            if (nums[mid] < target) {
                left = mid + 1;
            }else{
                right = mid;
            }
        }
        if(nums[left] == target){
            arr[0] = left;
        }




        //寻找右端点
        left = 0;
        right = nums.length - 1;
        while (left < right) {
            mid = (left + (right - left + 1)/2);
            if (nums[mid] > target) {
                right = mid - 1;
            }else {
                left = mid;
            }

        }
        if(nums[right] == target){
            arr[1] = right;
        }
        return arr;
    }
}